<template>
  <div class="floating"
       v-drag>
    <div class="menu"
         v-if="isShow">
      <span v-for="(item, index) in menu"
            :key="index"
            :class="{'active': active == index}"
            @click="menuSwitch(index)">{{item}}</span>
    </div>
    <div class="float-ball">
      <div class="colours"
           @click="menuShow">
        <div class="core">
          <img src="../../static/images/grid.png"
               alt="请等待">
          <span>菜单</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: 'Floating',
  props: ['index'],
  data () {
    return {
      active: 0,
      isShow: false,
      menu: ['护士站白板', '患者列表', '交班管理', '护士排班']
    }
  },
  mounted () {
    this.active = this.index
  },
  methods: {
    menuSwitch (ind) {
      this.active = ind
      switch (ind) {
        case 0:
          this.$router.push({path: '/', query: {index: ind}})
          break
        case 1:
          this.$router.push({path: '/PatientList', query: {index: ind}})
          break
        case 2:
          this.$router.push({path: '/ManageSuccession', query: {index: ind}})
          break
        case 3:
          this.$router.push({path: '/WorkforceManage', query: {index: ind}})
      }
    },
    menuShow () {
      this.isShow = !this.isShow
    }
  }
}
Vue.directive('drag', function (el) {
  el.onmousedown = function (e) {
    // var divx = e.clientX - el.offsetLeft
    var divy = e.clientY - el.offsetTop
    document.onmousemove = function (e) {
      // 获取移动后div的位置：鼠标位置-divx/divy
      // var l = e.clientX - divx
      var t = e.clientY - divy
      el.style.right = 0 + 'px'
      el.style.top = t + 'px'
    }
    document.onmouseup = function (e) {
      document.onmousemove = null
      document.onmouseup = null
    }
  }
})
</script>

<style lang="stylus" scoped>
.floating
  display flex
  position absolute
  right 0
  bottom 3rem
  align-items center
  height 1.36rem
  .menu
    width 3.24rem
    margin-right 0.2rem
    border 1px solid rgb(18, 19, 20)
    font-size 0.24rem
    background-color rgba(19, 22, 30, 0.839)
    box-shadow 0px 4px 16px 0px rgba(0, 0, 0, 0.79)
    span
      display inline-block
      width: 50%;
      height 0.67rem
      line-height 0.68rem
      text-align center
      color rgb(183, 189, 197)
      &:nth-child(1)
        border-bottom 1px solid rgb(18, 19, 20)
        border-right 1px solid rgb(18, 19, 20)
      &:nth-child(2)
        border-bottom 1px solid rgb(18, 19, 20)
      &:nth-child(3)
        border-right 1px solid rgb(18, 19, 20)
    .active
      color #fff
  .float-ball
    border 1px solid rgb(18, 19, 20)
    background-color rgba(42, 50, 67, 1)
    // box-shadow: 0px 8px 23.28px 0.72px rgba(0, 0, 0, 0.73)
    box-sizing border-box
    border-radius 50%
    width 0.96rem
    height 0.96rem
    text-align center
    padding 4px
    .colours
      width 100%
      height 100%
      box-sizing border-box
      border-radius 50%
      padding 2px
      background-image -webkit-linear-gradient(left, #57d9a1 25%, #51bda1 50%, #36c0e3 75%, #2dbbf7 100%)
      .core
        background-color rgba(42, 50, 67, 1)
        width 100%
        height 100%
        border-radius 50%
        color #fff
        img
          width 0.32rem
          height 0.32rem
          margin-top 0.1rem
        span
          display block
          font-size 0.2rem
          margin-top 0.05rem
</style>
